package client.view;
import java.awt.BorderLayout;
import java.awt.List;
import java.awt.TextArea;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;

import javax.swing.JButton;
import javax.swing.JFrame;

import client.remotes.ICommunicator;

import server.model.meeting.Message;

public class MeetingGui extends UnicastRemoteObject implements ICommunicator  {	
	
	private TextArea txtMessage; 
	private TextArea txtCompose;
	private List participants;
	private JButton btnSend;
	private ClientMeeting clientMeeting;
	private String blaat;
	private JFrame frame;
	private String username;
	

	public MeetingGui(ClientMeeting clientMeeting, String username) throws RemoteException{
		this.username = username;
		this.clientMeeting = clientMeeting;
		frame = new JFrame();
		frame.setSize(400, 400);
		frame.setVisible(true);
		frame.setLayout(null);
		
		initGUI();
	}
	
	private void initGUI() {
			
		txtMessage = new TextArea("voeg toe:");
		txtMessage.setEditable(false);
		txtMessage.setBounds(22, 12, 238, 249);
		
		txtCompose = new TextArea(); 
		txtCompose.setBounds(22, 273, 239, 77);		
		
		participants = new List();
		participants.setBounds(272, 12, 100, 120);		
		
		btnSend = new JButton("Send");
		btnSend.setBounds(273, 273, 100, 78);	
		
		btnSend.addActionListener(new btnSendListener());
		
		frame.getContentPane().add(txtCompose);
		frame.getContentPane().add(txtMessage);
		frame.getContentPane().add(participants);		
		frame.getContentPane().add(btnSend);
		
						
	}

	
	private class btnSendListener implements ActionListener{

		public void actionPerformed(ActionEvent arg0) {
			
			Message message = new Message(0, username , txtCompose.getText());

			txtCompose.setText("");
			
			clientMeeting.sendMessage(message);
			
		}
	}

	public void SendMessage(Message msg) throws RemoteException {
		txtMessage.append(msg.getSender()+" zegt: "+msg.getContent()+"\n");
		
	}



}
